﻿using System;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Cil;
using ProjScan.Modules;
using ProjScan.Tools;
using UnityEngine;

namespace ProjScan.RecordManager.AssetData
{
	// Token: 0x020002AD RID: 685
	internal class TypeDefinitionAssetData : AssetDataBase
	{
		// Token: 0x060011C8 RID: 4552 RVA: 0x000087B3 File Offset: 0x000069B3
		public TypeDefinitionAssetData(string assetName, TypeDefinition typeDefinition)
		{
			this.assetName = assetName;
			this.typeDefinition = typeDefinition;
			this.ConfigureAssetData();
		}

		// Token: 0x060011C9 RID: 4553 RVA: 0x000539F0 File Offset: 0x00051BF0
		private void ConfigureAssetData()
		{
			try
			{
				this.path = this.GetPath();
				bool flag = !string.IsNullOrEmpty(this.path);
				if (flag)
				{
					this.filePath = Path.GetFileName(this.path);
					this.dirPath = Path.GetDirectoryName(this.path);
				}
			}
			catch (ArgumentException ex)
			{
				ScanLog.Instance.LogInfo(ScanLog.LogLevel.EXCEPTION, Module.CS_Check, "ScriptRecord", string.Concat(new string[]
				{
					(ex.GetType() == null) ? null : ex.GetType().ToString(),
					"\n",
					ex.Message,
					"\n",
					ex.StackTrace
				}));
				Debug.LogError("Invalid path: " + this.path);
			}
		}

		// Token: 0x060011CA RID: 4554 RVA: 0x00053AD0 File Offset: 0x00051CD0
		public bool IsDerivedFromMonoBehaviour()
		{
			TypeReference baseType = this.typeDefinition;
			while (baseType != null)
			{
				bool flag = baseType.FullName == "UnityEngine.MonoBehaviour";
				if (flag)
				{
					return true;
				}
				try
				{
					baseType = baseType.Resolve().BaseType;
				}
				catch (Exception ex)
				{
					ScanLog.Instance.LogInfo(ScanLog.LogLevel.EXCEPTION, Module.CS_Check, "ScriptRecord:  " + baseType.FullName, string.Concat(new string[]
					{
						(ex.GetType() == null) ? null : ex.GetType().ToString(),
						"\n",
						ex.Message,
						"\n",
						ex.StackTrace
					}));
					break;
				}
			}
			return false;
		}

		// Token: 0x060011CB RID: 4555 RVA: 0x00053BA8 File Offset: 0x00051DA8
		private string GetPath()
		{
			string text = "";
			foreach (MethodDefinition methodDefinition in this.typeDefinition.Methods)
			{
				bool hasBody = methodDefinition.HasBody;
				if (hasBody)
				{
					foreach (Instruction instruction in methodDefinition.Body.Instructions)
					{
						SequencePoint sequencePoint = methodDefinition.DebugInformation.GetSequencePoint(instruction);
						bool flag = sequencePoint != null;
						if (flag)
						{
							text = sequencePoint.Document.Url;
							break;
						}
					}
					bool flag2 = !string.IsNullOrEmpty(text);
					if (flag2)
					{
						break;
					}
				}
			}
			return text;
		}

		// Token: 0x060011CC RID: 4556 RVA: 0x00053CA8 File Offset: 0x00051EA8
		public override string GetCSVHeader()
		{
			return "Class";
		}

		// Token: 0x060011CD RID: 4557 RVA: 0x00053CC0 File Offset: 0x00051EC0
		public override string GetInfo()
		{
			return ToolsHelper.QuoteString(this.assetName);
		}

		// Token: 0x060011CE RID: 4558 RVA: 0x000087E0 File Offset: 0x000069E0
		public override void Reset()
		{
			this.typeDefinition = null;
		}

		// Token: 0x060011CF RID: 4559 RVA: 0x00053CE0 File Offset: 0x00051EE0
		public override string GetAssetPath()
		{
			return this.path;
		}

		// Token: 0x060011D0 RID: 4560 RVA: 0x00053CF8 File Offset: 0x00051EF8
		public override string GetFileAssetPath()
		{
			return ToolsHelper.ConvertAbsolutePathToRelative(this.path);
		}

		// Token: 0x04000A94 RID: 2708
		public string assetName;

		// Token: 0x04000A95 RID: 2709
		public string filePath;

		// Token: 0x04000A96 RID: 2710
		public TypeDefinition typeDefinition;

		// Token: 0x04000A97 RID: 2711
		public string dirPath = null;

		// Token: 0x04000A98 RID: 2712
		public string path = null;
	}
}
